package com.pdg.islandinterloper.database.baseclasses;

import com.pdg.islandinterloper.baseclasses.ActivityClientBase;
import com.pdg.islandinterloper.database.interfaces.TableProvider;
import com.pdg.islandinterloper.interfaces.ActivityClient;

import android.app.Activity;
import android.database.sqlite.SQLiteDatabase;

public abstract class TableProviderBase<T extends Activity,U extends ActivityClient<T>> extends ActivityClientBase<T> implements TableProvider {

	private U parent;

	public TableProviderBase(U theParent) {
		super(theParent.getActivity());
		setParent(theParent);
	}

	private void setParent(U theParent) {
		parent = theParent;
	}
	
	public U getParent(){
		return parent;
	}

	@Override
	public abstract void onCreate(SQLiteDatabase theDatabase);

	public abstract void onUpgrade(SQLiteDatabase theDatabase, int theOldVersion, int theNewVersion);
	
	protected String integerFieldValue(int theValue) {
		return String.format("%d", theValue);
	}

	protected String stringFieldValue(String theValue) {
		return theValue.replace("'","''");
	}

}
